package com.bootdo.wx.controller;

import com.bootdo.wx.domain.GoodsTypeParamsDO;
import com.bootdo.wx.service.GoodsTypeParamsService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 类型参数名称
 * 
 * @author sys
 * @email 1992lcg@163.com
 * @date 2019-03-19 16:39:23
 */
 
@Controller
@RequestMapping("/wx/goodsTypeParams")
public class GoodsTypeParamsController {
	@Autowired
	private GoodsTypeParamsService goodsTypeParamsService;
	
	@GetMapping()
	@RequiresPermissions("wx:goodsTypeParams:goodsTypeParams")
	String GoodsTypeParams(){
	    return "wx/goodsTypeParams/goodsTypeParams";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wx:goodsTypeParams:goodsTypeParams")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<GoodsTypeParamsDO> goodsTypeParamsList = goodsTypeParamsService.list(query);
		int total = goodsTypeParamsService.count(query);
		PageUtils pageUtils = new PageUtils(goodsTypeParamsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wx:goodsTypeParams:add")
	String add(){
	    return "wx/goodsTypeParams/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wx:goodsTypeParams:edit")
	String edit(@PathVariable("id") String id,Model model){
		GoodsTypeParamsDO goodsTypeParams = goodsTypeParamsService.get(id);
		model.addAttribute("goodsTypeParams", goodsTypeParams);
	    return "wx/goodsTypeParams/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wx:goodsTypeParams:add")
	public R save( GoodsTypeParamsDO goodsTypeParams){
		if(goodsTypeParamsService.save(goodsTypeParams)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wx:goodsTypeParams:edit")
	public R update( GoodsTypeParamsDO goodsTypeParams){
		goodsTypeParamsService.update(goodsTypeParams);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wx:goodsTypeParams:remove")
	public R remove( String id){
		GoodsTypeParamsDO goodsTypeParamsDO = goodsTypeParamsService.get(id);
		goodsTypeParamsDO.setDelFlag(1);
		goodsTypeParamsDO.setGmtModified(new Date());
		if(goodsTypeParamsService.update(goodsTypeParamsDO)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wx:goodsTypeParams:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		for (String id : ids) {
			GoodsTypeParamsDO goodsTypeParamsDO = goodsTypeParamsService.get(id);
			goodsTypeParamsDO.setDelFlag(1);
			goodsTypeParamsDO.setGmtModified(new Date());
			goodsTypeParamsService.update(goodsTypeParamsDO);
		}
		return R.ok();
	}
	
}
